using UnityEngine;
using TMPro;

namespace HEFramework
{
    /// <summary>
    ///
    /// [TMP]UI文本行为基类
    /// 
    /// ----------------------------------------
    /// 作者 hep
    /// 创建时间：2023-02-17 17:30:30
    /// ----------------------------------------
    /// </summary>
    [RequireComponent(typeof(TextMeshProUGUI))]
    public class UITMPTextBehaviourBase : MonoBehaviour, IUITMPTextBehaviour
    {
        private TMP_Text text;

        private Color color;

        public TMP_Text Text => text;


        public void Awake()
        {
            if (text == null)
            {
                text = transform.GetComponent<TMP_Text>();
            }
        }

        public Transform GetTransform()
        {
            return text.transform;
        }

        /// <summary>
        /// 返回对象
        /// </summary>
        /// <returns></returns>
        public GameObject GetGameObject()
        {
            return text.gameObject;
        }

        public IUITMPTextBehaviour SetText(string _text)
        {
            text.text = _text;
            return this;
        }

        public IUITMPTextBehaviour SetColor(int _r, int _g, int _b, int _a)
        {
            color.r = _r;
            color.g = _g;
            color.b = _b;
            color.a = _a;
            text.color = color;
            return this;
        }
    }
}